package com.shanwen.shopping.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shanwen.shopping.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 商品支付页面
 */
public class OrderPayActivity extends AppBaseActivity {

    @BindView(R.id.tvTotalPrice)
    TextView tvTotalPrice;
    @BindView(R.id.ivBank)
    ImageView ivBank;
    @BindView(R.id.ivZhiFuBao)
    ImageView ivZhiFuBao;
    @BindView(R.id.ivWeiXin)
    ImageView ivWeiXin;
    @BindView(R.id.ivNongHang)
    ImageView ivNongHang;
    private int curPos = -1;
    private List<ImageView> ivList = new ArrayList<>();
    private final int BANK = 0, ZHIFUBAO = 1, WEIXIN = 2, NONGHANG = 3;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_order_pay;
    }

    @Override
    public void initView() {
        super.initView();
        setTitle("订单支付");
        setBackEnabled(true);
        tvTotalPrice.setText(getIntent().getStringExtra("price"));
        ivList.add(ivBank);
        ivList.add(ivZhiFuBao);
        ivList.add(ivWeiXin);
        ivList.add(ivNongHang);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @OnClick({R.id.ivBank, R.id.ivZhiFuBao, R.id.ivWeiXin, R.id.ivNongHang})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivBank:
                setIvChecked(BANK);
                break;
            case R.id.ivZhiFuBao:
                setIvChecked(ZHIFUBAO);
                break;
            case R.id.ivWeiXin:
                setIvChecked(WEIXIN);
                break;
            case R.id.ivNongHang:
                setIvChecked(NONGHANG);
                break;
        }
    }

    public void setIvChecked(int pos) {
        if (curPos != pos) {
            for (int i = 0; i < ivList.size(); i++) {
                if (i == pos) {
                    ivList.get(i).setImageResource(R.mipmap.pay_checked);
                } else {
                    ivList.get(i).setImageResource(R.mipmap.pay_unchecked);
                }
            }
            curPos = pos;
        }
    }
}
